package com.jadows.tdog.configuration;

import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.service.alimt20181012.AsyncClient;
import com.jadows.tdog.properties.TranslateProperties;
import darabonba.core.client.ClientOverrideConfiguration;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

@Configuration
@RequiredArgsConstructor
public class AliTranslateConfiguration {

    final TranslateProperties translateProperties;


    @Bean
    public AsyncClient translateClient() {
        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                .accessKeyId(translateProperties.getAccessKeyId())
                .accessKeySecret(translateProperties.getAccessKeySecret())
                .build());
        return AsyncClient.builder()
                .credentialsProvider(provider)
                .overrideConfiguration(
                        ClientOverrideConfiguration.create()
                                .setEndpointOverride("mt.cn-hangzhou.aliyuncs.com")
                                .setConnectTimeout(Duration.ofSeconds(30))
                )
                .build();
    }

}
